{{define "header"}}
<link rel="stylesheet" type="text/css" href="junit.css">
<script type="text/javascript" src="script_bundle.min.js"></script>
{{end}}

{{define "body"}}
{{$numF := len .Failed}}
{{$numFlk := len .Flaky}}
{{$numP := len .Passed}}
{{$numS := len .Skipped}}
{{if eq .NumTests 0}}
  <div id="empty-junit-container">
    No tests were recorded.
  </div>
{{else}}
<div id="junit-container">
  <table id="junit-table" class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
  {{if gt $numF 0}}
  <tr id="failed-theader" class="header section-expander">
    <td class="mdl-data-table__cell--non-numeric expander failed" colspan="1"><h6>{{len .Failed}}/{{.NumTests}} Tests Failed.</h6></td>
    <td class="mdl-data-table__cell--non-numeric expander"><i id="failed-expander" class="icon-button material-icons arrow-icon noselect">expand_less</i></td>
  </tr>
  <tbody id="failed-tbody">
    {{range $ix, $test := .Failed}}
      {{$numTest := len $test.Junit}}
      {{$firstTest := index $test.Junit 0}}
      {{if eq $numTest 1}}
      <tr>
        <td colspan="2" style="padding: 0;">
          <table class="failed-layout">
            <tr class="failure-name">
              <td class="mdl-data-table__cell--non-numeric test-name">{{$firstTest.ClassName}}: {{$firstTest.Name}}&nbsp;<i class="icon-button material-icons arrow-icon">expand_more</i></td>
              <td class="mdl-data-table__cell--non-numeric" style="text-align: right;">{{$firstTest.Duration}}</td>
            </tr>
            <tr class="hidden failure-text">
              <td colspan="2" class="mdl-data-table__cell--non-numeric">
                <div>{{$firstTest.Failure}}</div>
                {{if $firstTest.Output}}
                <a href="#" class="open-stdout-stderr">open stdout<i class="material-icons" style="font-size: 1em; vertical-align: middle; padding-left: 3px;">open_in_new</i></a>
                <pre style="display: none;">{{$firstTest.Output}}</pre>
                {{end}}
                {{if $firstTest.Error}}
                <a href="#" class="open-stdout-stderr">open stderr<i class="material-icons" style="font-size: 1em; vertical-align: middle; padding-left: 3px;">open_in_new</i></a>
                <pre style="display: none;">{{$firstTest.Error}}</pre>
                {{end}}
              </td>
            </tr>
          </table>
        </td>
      </tr>
      {{else}}
      <tr>
        <td colspan="2" style="padding: 0;">
          <table class="failed-layout">
            <tr class="failure-name">
              <td class="mdl-data-table__cell--non-numeric test-name">{{$firstTest.ClassName}}: {{$firstTest.Name}}&nbsp;<i class="icon-button material-icons arrow-icon">expand_more</i></td>
            </tr>
            <tr class="hidden">
              <td>
                <table  class="failed-layout">
                  {{range $ixt, $indTest := $test.Junit}}
                  <tr  class="failure-text">
                    <td colspan="2" style="padding: 0;">
                      <table class="failed-layout">
                        <tr class="failure-name">
                          <td class="mdl-data-table__cell--non-numeric test-name">Run #{{$ixt}}: {{$indTest.Status}}&nbsp;<i class="icon-button material-icons arrow-icon">expand_more</i></td>
                          <td class="mdl-data-table__cell--non-numeric" style="text-align: right;">{{$indTest.Duration}}</td>
                        </tr>
                        <tr class="hidden failure-text">
                          <td colspan="2" class="mdl-data-table__cell--non-numeric">
                            <div>{{$indTest.Failure}}</div>
                            {{if $indTest.Output}}
                            <a href="#" class="open-stdout-stderr">open stdout<i class="material-icons" style="font-size: 1em; vertical-align: middle; padding-left: 3px;">open_in_new</i></a>
                            <pre style="display: none;">{{$indTest.Output}}</pre>
                            {{end}}
                            {{if $indTest.Error}}
                            <a href="#" class="open-stdout-stderr">open stderr<i class="material-icons" style="font-size: 1em; vertical-align: middle; padding-left: 3px;">open_in_new</i></a>
                            <pre style="display: none;">{{$indTest.Error}}</pre>
                            {{end}}
                          </td>
                        </tr>
                      </table>
                    </td>
                  </tr>
                  {{end}}
                </table>
              </td>
            </tr>
          </table>
        </td>
      </tr>
      {{end}}
    {{end}}
  </tbody>
  {{end}}
  {{if gt $numFlk 0}}
  <tr id="flaky-theader" class="header section-expander">
    <td class="mdl-data-table__cell--non-numeric expander flaky" colspan="1"><h6>{{len .Flaky}}/{{.NumTests}} Tests Flaky.</h6></td>
    <td class="mdl-data-table__cell--non-numeric expander"><i id="flaky-expander" class="icon-button material-icons arrow-icon noselect">expand_less</i></td>
  </tr>
  <tbody id="flaky-tbody">
    {{range $ix, $test := .Flaky}}
      {{$firstTest := index $test.Junit 0}}
      <tr>
        <td colspan="2" style="padding: 0;">
          <table class="flaky-layout">
            <tr class="flaky-name">
              <td class="mdl-data-table__cell--non-numeric test-name">{{$firstTest.ClassName}}: {{$firstTest.Name}}&nbsp;<i class="icon-button material-icons arrow-icon">expand_more</i></td>
            </tr>
            <tr class="hidden">
              <td>
                <table class="flaky-layout">
                  {{range $ixt, $indTest := $test.Junit}}
                  <tr  class="flaky-text">
                    <td colspan="2" style="padding: 0;">
                      <table class="flaky-layout">
                        <tr class="flaky-name">
                          <td class="mdl-data-table__cell--non-numeric test-name">Run #{{$ixt}}: {{$indTest.Status}}&nbsp;<i class="icon-button material-icons arrow-icon">expand_more</i></td>
                          <td class="mdl-data-table__cell--non-numeric" style="text-align: right;">{{$indTest.Duration}}</td>
                        </tr>
                        <tr class="hidden flaky-text">
                          <td colspan="2" class="mdl-data-table__cell--non-numeric">
                            <div>{{$indTest.Failure}}</div>
                            {{if $indTest.Output}}
                            <a href="#" class="open-stdout-stderr">open stdout<i class="material-icons" style="font-size: 1em; vertical-align: middle; padding-left: 3px;">open_in_new</i></a>
                            <pre style="display: none;">{{$indTest.Output}}</pre>
                            {{end}}
                            {{if $indTest.Error}}
                            <a href="#" class="open-stdout-stderr">open stderr<i class="material-icons" style="font-size: 1em; vertical-align: middle; padding-left: 3px;">open_in_new</i></a>
                            <pre style="display: none;">{{$indTest.Error}}</pre>
                            {{end}}
                          </td>
                        </tr>
                      </table>
                    </td>
                  </tr>
                  {{end}}
                </table>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    {{end}}
  </tbody>
  {{end}}
  {{if gt $numP 0}}
    <tr id="passed-theader" class="header section-expander">
      <td class="mdl-data-table__cell--non-numeric expander passed" colspan="1"><h6>{{len .Passed}}/{{.NumTests}} Tests Passed!</h6></td>
      <td class="mdl-data-table__cell--non-numeric expander"><i id="passed-expander" class="icon-button material-icons arrow-icon noselect">expand_more</i></td>
    </tr>
    <tbody id="passed-tbody" class="hidden-tests">
      {{range .Passed}}
        {{$firstTest := index .Junit 0}}
        <tr>
          <td class="mdl-data-table__cell--non-numeric test-name">{{$firstTest.ClassName}}: {{$firstTest.Name}}</td>
          <td class="mdl-data-table__cell--non-numeric">{{$firstTest.Duration}}</td>
        </tr>
      {{end}}
    </tbody>
  {{end}}
  {{if gt $numS 0}}
    <tr id="skipped-theader" class="header section-expander">
      <td class="mdl-data-table__cell--non-numeric expander skipped" colspan="1"><h6>{{len .Skipped}}/{{.NumTests}} Tests Skipped.</h6></td>
      <td class="mdl-data-table__cell--non-numeric expander"><i id="skipped-expander" class="icon-button material-icons arrow-icon noselect">expand_more</i></td>
    </tr>
    <tbody id="skipped-tbody" class="hidden-tests">
      {{range .Skipped}}
        {{$firstTest := index .Junit 0}}
        <tr>
	   {{if eq $firstTest.SkippedReason "" }}
	   <td class="mdl-data-table__cell--non-numeric test-name">{{$firstTest.ClassName}}: {{$firstTest.Name}}</td>
	   {{else}}
	   <td class="mdl-data-table__cell--non-numeric test-name">{{$firstTest.ClassName}}: {{$firstTest.Name}}</br> </br><b>Reason:</b> {{$firstTest.SkippedReason}}</td>
	   {{end}}
          <td class="mdl-data-table__cell--non-numeric">{{$firstTest.Duration}}</td>
        </tr>
      {{end}}
    </tbody>
  {{end}}
  </table>
</div>
{{end}}
{{end}}

